package com.hl.apple.myapplication

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.HttpHeaders
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response

class QQMusicData : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_douyin)
        initView()
    }

    private fun initView() {
        Http("桃花朵朵开")
    }

    fun Http(key: String) {

        val headers = HttpHeaders()
        headers.put("Host", "c.y.qq.com")    //header不支持中文，不允许有特殊字符
        headers.put("Referer", "http://c.y.qq.com/")
        headers.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 '\n" +
                "                  'Safari/537.36 '")


        var param = HttpParams()
        param.put("w", key)

        OkGo.get<String>(Constant.QQMUSICURL)
                .headers(headers)
                .params(param)
                .execute(object : StringCallback() {
                    override fun onSuccess(response: Response<String>) {
                        Log.e("哈哈啊哈", "=====" + response.body())
                    }

                    override fun onError(response: Response<String>?) {
                        super.onError(response)
                        Log.e("错错错", "=====" + response?.code())

                    }


                })
    }


}